import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import dotenv from 'dotenv'

dotenv.config({ path: '.env.' + process.env.NODE_ENV })

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/dev': {
        target: process.env.VITE_API_SERVER,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev/, '')
      },
      '/test': {
        target: process.env.VITE_API_SERVER,
        rewrite: (path) => path.replace(/^\/test/, '')
      },
      '/apk': {
        target: process.env.VITE_API_SERVER,
        rewrite: (path) => path.replace(/^\/apk/, '')
      }
    }
},
})
